package com.liliudong.template.api.admin.controller.sys;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.liliudong.template.biz.service.sys.SysDictService;
import com.liliudong.template.common.R;
import com.liliudong.template.common.request.sys.SysDictAddRequest;
import com.liliudong.template.common.request.sys.SysDictModifyRequest;
import com.liliudong.template.common.request.sys.SysDictPageRequest;
import com.liliudong.template.common.response.sys.SysDictDetailResponse;
import com.liliudong.template.common.response.sys.SysDictListResponse;
import com.liliudong.template.common.response.sys.SysDictPageResponse;
import com.mybatisflex.core.paginate.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 *
 * @author liudo
 * @date 2024-08-01 20:17:12
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sys/dict")
public class SysDictController {

	private final SysDictService sysDictService;

	/**
	 * 添加
	 *
	 * @param sysDictAddRequest 新增dto
	 * @return {@link R }<{@link ? }>
	 */
	@SaCheckPermission("sys:dict:add")
	@PostMapping
	public R<?> addOne(@RequestBody @Validated SysDictAddRequest sysDictAddRequest) {
		sysDictService.addOne(sysDictAddRequest);
		return R.ok();
	}

	/**
	 * 删除
	 *
	 * @param id 主键
	 * @return {@link R }<{@link ? }>
	 */
	@SaCheckPermission("sys:dict:delete")
	@DeleteMapping("/{id}")
	public R<?> deleteById(@PathVariable Long id) {
		sysDictService.deleteById(id);
		return R.ok();
	}

	/**
	 * 修改
	 *
	 * @param id 主键
	 * @param sysDictModifyRequest 更新dto
	 * @return {@link R }<{@link ? }>
	 */
	@SaCheckPermission("sys:dict:modify")
	@PutMapping("/{id}")
	public R<?> modifyById(@PathVariable Long id,
	                       @RequestBody @Validated SysDictModifyRequest sysDictModifyRequest) {
		sysDictService.modifyById(id, sysDictModifyRequest);
		return R.ok();
	}

	/**
	 * 详情
	 *
	 * @param id 主键
	 * @return {@link R }<{@link SysDictDetailResponse }>
	 */
	@SaCheckPermission("sys:dict:detail")
	@GetMapping("/detail/{id}")
	public R<SysDictDetailResponse> detailById(@PathVariable Long id) {
		SysDictDetailResponse sysDictDetailVO = sysDictService.detailById(id);
		return R.ok(sysDictDetailVO);
	}

	/**
	 * 分页查询
	 * @param page            				 页面
	 * @param size            				 大小
	 * @param sysDictPageRequest 分页查询条件
	 * @return {@link R }<{@link Page< SysDictPageResponse > }>
	 */
	@SaCheckPermission("sys:dict:list")
	@GetMapping("/page/{page}/{size}")
	public R<Page<SysDictPageResponse>> queryPage(@PathVariable Long page, @PathVariable Long size, SysDictPageRequest sysDictPageRequest) {
		Page<SysDictPageResponse> pageData = sysDictService.queryPage(page, size, sysDictPageRequest);
		return R.ok(pageData);
	}

	/**
	 * 查询列表
	 *
	 * @return {@link R }<{@link SysDictListResponse }>
	 */
	@SaCheckLogin
	@GetMapping("/list")
	public R<List<SysDictListResponse>> queryList() {
		List<SysDictListResponse> list = sysDictService.queryList();
		return R.ok(list);
	}
}
